//
//  AppDelegate.swift
//  weibo
//
//  Created by  郭航 on 16/6/23.
//  Copyright © 2016年 郭航. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        window = UIWindow()

        setAppTint()
        
        if WBUserInfor.shareWBUserInfor.isLogin {
            window?.rootViewController = WBWelcomeViewController()
        } else {
            window?.rootViewController = WBMainViewController()
        }

        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.changeKeyWindows(_:)), name: NotChangeKeyWindows, object: nil)
        
        window?.makeKeyAndVisible()
        return true
    }
    
    func setAppTint() -> () {
        UITabBar.appearance().tintColor = APPTintColor
        UINavigationBar.appearance().tintColor = APPTintColor
    }

    func changeKeyWindows(not: NSNotification) -> Void {
        let str = not.object
        
        if str as! String == "welcome" {
            window?.rootViewController = WBMainViewController()
        } else if str as! String == "login" {
            window?.rootViewController = WBWelcomeViewController()
        }
    }
    
    func applicationDidEnterBackground(application: UIApplication) {
        WBCacheTool.deleteCache()
    }
    
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
}

